rm(list = ls())
library(foreign)
library(readstata13)

states <- read.dta13("Barber_Bolton_Thrower_Replication_Data_LSQ.dta")

states$veto_proof_opposed <- ifelse(states$veto_proof == 1 & states$divided_gov1 == 1, 1, 0)
states$veto_proof_opposed[is.na(states$veto_proof)] <- NA
states$veto_proof_opposed[is.na(states$divided_gov1)] <- NA

veto_proof_opposition <- tapply(states$veto_proof_opposed, states$year, function(x) mean(x, na.rm =T))
veto_proof_opposition <- veto_proof_opposition[c(5:25)]

states$divided_notveto <- ifelse(states$divided_gov1 == 1 & states$veto_proof == 0, 1, 0)
divided_notveto <- tapply(states$divided_notveto, states$year, function(x) mean(x, na.rm =T))
divided_notveto <- divided_notveto[c(5:25)]

divided_government <- tapply(states$divided_gov1, states$year, function(x) mean(x, na.rm =T))
divided_government <- divided_government[c(5:25)]


dev.new(width = 10, height = 5)
plot(1993:2013, veto_proof_opposition, pch = 16, ylim = c(0, .6), ylab = "Percent of States", xlab = "Year", xlim = c(1989, 2013), axes = F, main = "Executive - Legislature Partisan Composition")
lines(1993:2013, veto_proof_opposition)
points(1993:2013, divided_notveto, pch = 15)
lines(1993:2013, divided_notveto)
text(1993, divided_notveto[1], "Divided Government\n(Not Veto-Proof)", pos = 2, cex = .8)
text(1993, veto_proof_opposition[1], "Veto-Proof Opposition", pos = 2, cex = .8)
axis(2, at = seq(0, .7, .1), labels = seq(0, 70, 10), las = 2)
axis(1, at = seq(1993, 2013, 2))
box()